import Vue from "vue";
import Vuex from "vuex";
import axios from "axios";
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    list: [],
    carList: []
  },
  mutations: {
    setList(state, payload) {
      state.list = payload;
    },
    setCarList(state, payload) {
      state.carList = payload
    }
  },
  actions: {
    async fetchList(context) {
      const resp = await axios.get("/api/list");
      context.commit('setList', resp.data.data)
    },
    async fetchCarList(context) {
      const resp = await axios.get("/api/car");
      context.commit('setCarList', resp.data.data)
    }
  },
});
